package com.huatai.exchange.bootup.controller;

import com.faneui.bootup.controller.AbstractRestController;
import com.faneui.common.utils.BeanMapper;
import com.faneui.common.utils.ListUtils;
import com.huatai.exchange.dal.model.ExcFileLoadInfo;
import com.huatai.exchange.dal.model.ExcFileLoadRecord;
import com.huatai.exchange.facade.ExcFileLoadInfoController;
import com.huatai.exchange.facade.bean.FileLoadInfoVo;
import com.huatai.exchange.facade.bean.FileLoadRecordVo;
import com.huatai.exchange.facade.bean.QueryFileLoadInfoVoListResp;
import com.huatai.exchange.facade.bean.QueryFileLoadRecordVoListResp;
import com.huatai.exchange.service.ExcFileLoadInfoService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "loadinfo")
@Api("公共文件备份信息")
public class FileLoadInfoControllerImpl extends AbstractRestController implements ExcFileLoadInfoController {

    @Autowired
    private ExcFileLoadInfoService excFileLoadInfoService ;

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public QueryFileLoadInfoVoListResp queryFileLoadInfoVoList(@ModelAttribute FileLoadInfoVo fileLoadInfoVo) throws Exception {
        QueryFileLoadInfoVoListResp resp = new QueryFileLoadInfoVoListResp();
        try {
            ExcFileLoadInfo param = BeanMapper.map(fileLoadInfoVo, ExcFileLoadInfo.class);
            List<ExcFileLoadInfo> records = excFileLoadInfoService.queryExcFileLoadInfoList(param) ;
            if (ListUtils.isNotEmpty(records)) {
                List<FileLoadInfoVo> vos = BeanMapper.mapList(records, FileLoadInfoVo.class);
                resp.setFileLoadInfoVos(vos);
            }
        } catch (Exception ex) {
            logger.error("", ex);
            resp.setSuccess(false);
            resp.setMsg(ex.getMessage());
        }
        return resp;
    }


}
